package com.edu.exam.entity.curriculum.course;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 课程专业层次开设关联实体
 * 所属模块：B-01 课程管理模块
 * 对应设计文档：B-01-01-02-子模块类图设计.md
 *
 * 管理课程与专业层次开设的关联关系，包括关联类型、状态、权重系数等。
 * 支持课程在不同专业培养层次的开设管理，是课程管理的重要关联实体。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("课程专业层次开设关联表")
@Table(name = "course_major_level_offering_relations",
       uniqueConstraints = @UniqueConstraint(columnNames = {"course_id", "major_level_offering_id"},
                                                name = "uk_course_major_level_offering"))
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CourseMajorLevelOfferingRelation {

    /**
     * 关联ID，主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 课程ID，外键关联课程表
     */
    @NotNull(message = "课程ID不能为空")
    @Column(name = "course_id", nullable = false)
    private Long courseId;

    /**
     * 专业层次开设ID，外键关联专业层次开设表
     */
    @NotNull(message = "专业层次开设ID不能为空")
    @Column(name = "major_level_offering_id", nullable = false)
    private Long majorLevelOfferingId;

    /**
     * 关联类型，标识课程在该专业层次开设中的类型
     */
    @NotNull(message = "关联类型不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "relation_type", nullable = false, length = 50)
    private CourseRelationTypeEnum relationType;

    /**
     * 关联状态，标识关联关系的当前状态
     */
    @NotNull(message = "关联状态不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 50)
    @Builder.Default
    private CourseRelationStatusEnum status = CourseRelationStatusEnum.ACTIVE;

    /**
     * 关联描述，详细说明关联关系的内容
     */
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    /**
     * 权重系数，用于标识课程在专业培养方案中的重要性
     */
    @Column(name = "weight_coefficient", precision = 4, scale = 2)
    private Double weightCoefficient;

    /**
     * 难度等级，标识课程在该专业层次中的教学难度
     */
    @Size(max = 20, message = "难度等级长度不能超过20个字符")
    @Column(name = "difficulty_level", length = 20)
    private String difficultyLevel;

    /**
     * 生效时间，关联关系的开始生效时间
     */
    @Column(name = "effective_time")
    private LocalDateTime effectiveTime;

    /**
     * 失效时间，关联关系的结束时间，为空表示长期有效
     */
    @Column(name = "expiry_time")
    private LocalDateTime expiryTime;

    /**
     * 创建时间
     */
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    // 关联关系定义

    /**
     * 关联的课程实体
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "course_id", referencedColumnName = "id",
                nullable = false,
                foreignKey = @ForeignKey(name = "fk_course_major_relation_course"))
    private Course course;

    /**
     * 关联的专业层次开设实体
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "major_level_offering_id", referencedColumnName = "id",
                nullable = false,
                foreignKey = @ForeignKey(name = "fk_course_major_relation_offering"))
    private com.edu.exam.entity.curriculum.academic.MajorLevelOffering majorLevelOffering;
}